using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace GameFrameworkLibraly.Helpers
{
    class LoadHelper
    {
        readonly Dictionary<object, Texture2D> _textures = new Dictionary<object, Texture2D>();
        readonly Dictionary<object, SpriteFont> _fonts = new Dictionary<object, SpriteFont>();

        private readonly ContentManager _contentManager;

        public LoadHelper(ContentManager contentManager)
        {
            _contentManager = contentManager;
        }

        /// <summary>
        /// Loads all content in dictionaries
        /// </summary>
        public void Load(List<object> textures, List<object> fonts)
        {
            foreach (var font in fonts)
            {
                GetFont(font);
            }
            foreach (var texture in textures)
            {
                GetTexture(texture);
            }
        }

        /// <summary>
        /// Takes textures from the dictionary. If there are no such texture than loads it from hard drive.
        /// </summary>
        /// <param name="name">Texture's name from enum</param>
        /// <returns>Texture</returns>
        public Texture2D GetTexture(object name)
        {
            if (!_textures.ContainsKey(name))
                _textures.Add(name, _contentManager.Load<Texture2D>("Textures/" + name));
            return _textures[name];
        }


        /// <summary>
        /// Takes font from the dictionary. If there are no such font than loads it from hard drive.
        /// </summary>
        /// <param name="name">Font's name from enum</param>
        /// <returns>Font</returns>
        public SpriteFont GetFont(object name)
        {
            if (!_fonts.ContainsKey(name))
                _fonts.Add(name, _contentManager.Load<SpriteFont>("Fonts/" + name));
            return _fonts[name];
        }

    }


}

